package high.concurrent.controller;


import high.concurrent.request.LockProductRequest;
import high.concurrent.service.ProductService;
import high.concurrent.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 黄保泽
 * @since 2021-07-18
 */
@RestController
@RequestMapping("/api/product/v1/")
@Api(tags = "商品模块")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 商品列表查询: 注意返回商品库存需要库存-锁定库存
     * @param page    当前页数
     * @param size    每页条数
     * @return
     */
    @ApiOperation(value = "商品列表查询")
    @GetMapping("selectProductList")
    public JsonData selectProductList(@ApiParam(value = "当前页数") @RequestParam(value = "page", defaultValue = "1") Integer page,
                                      @ApiParam(value = "每页条数") @RequestParam(value = "size", defaultValue = "10") Integer size){

        JsonData jsonData = productService.selectProductList(page, size);
        return jsonData;
    }

    /**
     * 商品详情
     * @param productId    商品id
     * @return
     */
    @ApiOperation(value = "商品详情")
    @GetMapping("getProductDetail")
    public JsonData getProductDetail(@ApiParam(value = "商品id", required = true) @RequestParam(value = "product_id", required = true) Long productId){

        JsonData jsonData = productService.getProductDetail(productId);
        return jsonData;
    }

    /**
     * 购物车所有商品项锁定
     * @param lockProductRequest
     * @return
     */
    @ApiOperation(value = "商品锁定")
    @PostMapping("lockProduct")
    public JsonData lockProduct(@ApiParam("锁定商品项请求参数") @RequestBody LockProductRequest lockProductRequest){

        JsonData jsonData = productService.lockProd(lockProductRequest);
        return jsonData;
    }

}

